package top.wenzz.commons.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.web.csrf.CsrfToken;
import top.wenzz.commons.utils.SpringSecurityUtils;
import top.wenzz.commons.vo.RetMsg;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by 钟廷员 on 2016/12/19.
 */
public class BasicController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    protected RetMsg ret(String errorMsg, String successMsg) {
        return errorMsg == null ? RetMsg.success(successMsg) : RetMsg.error(errorMsg);
    }

    protected Map<String, Object> getUserData(HttpServletRequest request) {
        Map<String, Object> retData = SpringSecurityUtils.getWebUserData();
        retData.put("id", ((CsrfToken) request.getAttribute("_csrf")).getToken());
        return retData;
    }
}
